package fr.upstlse.glre.client.espacededie.commun.utilisateur;

import java.util.List;

import com.extjs.gxt.ui.client.binder.DataListBinder;
import com.extjs.gxt.ui.client.fx.Draggable;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.DataList;
import com.google.gwt.user.client.ui.Composite;

import fr.upstlse.glre.client.administration.communiquer.Communiquer;
import fr.upstlse.glre.client.constante.RfgConstanteEnum;
import fr.upstlse.glre.client.espacededie.commun.utilisateur.action.IUserSelectionAction;
import fr.upstlse.glre.client.espacededie.component.AbstractCenter;
import fr.upstlse.glre.client.vo.user.UserVOGWT;
import fr.upstlse.glre.client.widgets.modelData.UserModelData;

public abstract class AbstractListeUtilisateurs extends Composite {
	protected ContentPanel listeUserContentPanel;

	protected DataList listeUserPanel = new DataList();
	
	protected AbstractFilterBar filterBar;
	
	protected List<UserVOGWT> userVOGWTs;
	
	protected DataListBinder<UserModelData> binder;
	
	protected IUserSelectionAction iUserSelectionAction;
	
	protected static AbstractListeUtilisateurs instance;

	protected AbstractListeUtilisateurs() {
		createListeUserContentPanel();

		initWidget(listeUserContentPanel);
	}

	private void createListeUserContentPanel() {
		listeUserContentPanel = new ContentPanel();
		listeUserContentPanel.setAutoWidth(true);
		listeUserContentPanel.setWidth(500);
		listeUserContentPanel.setId(RfgConstanteEnum.LISTEUSER_CONTENTPANEL_ID
				.getValue());
		listeUserContentPanel.setBorders(true);

		// Draggable panel
		Draggable lDraggable = new Draggable(listeUserContentPanel,
				listeUserContentPanel.getHeader());
		lDraggable.setContainer(AbstractCenter.getInstance());

		listeUserContentPanel
				.setHeading(RfgConstanteEnum.LISTEUSER_CONTENTPANEL_HEADER_TEXT
						.getValue());
		
		initContentPanel();
	}

	public void createListeUserPanel() {
		listeUserPanel.setStyleName("listeUserPanel");
		listeUserPanel.setFlatStyle(true);
		initList();
		if(filterBar != null) {
			listeUserContentPanel.getHeader().addTool(filterBar);
		}
	}
	
	public ContentPanel getListeUserContentPanel() {
		return listeUserContentPanel;
	}

	public void setListeUserContentPanel(ContentPanel listeUserContentPanel) {
		this.listeUserContentPanel = listeUserContentPanel;
	}

	public DataList getListeUserPanel() {
		return listeUserPanel;
	}

	public void setListeUserPanel(DataList listeUserPanel) {
		this.listeUserPanel = listeUserPanel;
	}

	public List<UserVOGWT> getUserVOGWTs() {
		return userVOGWTs;
	}

	public void setUserVOGWTs(List<UserVOGWT> userVOGWTs) {
		this.userVOGWTs = userVOGWTs;
	}
	
	protected abstract void initContentPanel();
	
	protected abstract void initList();
	
	public void setUserSelectionAction(IUserSelectionAction pIUserSelectionAction) {
		iUserSelectionAction = pIUserSelectionAction;
	}
	
	public static AbstractListeUtilisateurs getInstance() {
		return instance;
	}

	public static void setInstance(Communiquer instance) {
		AbstractListeUtilisateurs.instance = instance;
	}

	public AbstractFilterBar getFilterBar() {
		return filterBar;
	}

	public void setFilterBar(AbstractFilterBar filterBar) {
		this.filterBar = filterBar;
	}

	public IUserSelectionAction getIUserSelectionAction() {
		return iUserSelectionAction;
	}

	public void setIUserSelectionAction(IUserSelectionAction userSelectionAction) {
		iUserSelectionAction = userSelectionAction;
	}

	public DataListBinder<UserModelData> getBinder() {
		return binder;
	}

	public void setBinder(DataListBinder<UserModelData> binder) {
		this.binder = binder;
	}
}
